home *** CD-ROM | disk | FTP | other *** search
- #include <Packages.h>
- #include <Folders.h>
-
- /*****
- * a structure used to pre-select a folder
- *****/
- typedef struct {
- FSSpec *theFile;
- StandardFileReply *theReply;
- } MyDataRecord;
-
-
- #define isDirectory 0x0010
- #define kReportDlgID 257
- #define kSFPutDlgID 256
-
-
- /*****
- * On first call through CustomGetFile(), set everything so folder specified in
- * myDataPtr->theFile is preselected
- *****/
- pascal short dlgHook(short item, DialogPtr theDialog, MyDataRecord *myDataPtr)
- {
- if (item == sfHookFirstCall)
- {
- myDataPtr->theReply->sfFile = *(myDataPtr->theFile);
-
- // the following line ensures the first subfolder in the folder specified
- // is selected. If we didn't nil out the name, the last subfolder would
- // be selected.
- myDataPtr->theReply->sfFile.name[0] = 0;
- myDataPtr->theReply->sfScript = 0;
- return sfHookChangeSelection;
- }
- return item;
- }
-
-
- /*****
- * Display a folder at the location specified by myFSSpec. The files within this
- * folder are grayed out. We return with a full FSSpec, or -1 if user hit cancel.
- *****/
- OSErr GetFileGray(FSSpec *myFSSpec)
- {
- OSErr err;
-
- MyDataRecord myData;
-
- /*
- * the default name is used in building a FSSpec for the reply. It must
- * not be passed in as a null string, or your "select this folder" button
- * won't ever be active.
- */
- Str255 defaultName = "\pMust Not Be Null";
- StandardFileReply reply;
- Point where = {-1, -1}; // autocenter, System 7!
- short activeList[2] = {1, 7}; // only keyboard on file list
-
- myData.theFile = myFSSpec;
- myData.theReply = &reply;
-
- CustomPutFile("\p",
- defaultName,
- &reply,
- kSFPutDlgID,
- where,
- (DlgHookYDProcPtr)dlgHook,
- nil,
- activeList,
- nil,
- &myData);
- if (reply.sfGood)
- err = FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, nil, myFSSpec);
- else
- err = -1; // return some arbitrary error telling us cancel was selected.
- return err;
- }
-
-
- /*****
- * Set up a file spec to point to System file in System Folder
- *****/
- OSErr SetUpFile(FSSpec *fileSpec)
- {
- OSErr err;
- short vRefNum;
- long dirID;
-
- err = FindFolder(kOnSystemDisk,kSystemFolderType,kDontCreateFolder, &vRefNum,&dirID);
-
- if (err) {
- DebugStr("\pFickle FindFolder failed to find fey folder");
- ExitToShell();
- }
-
- err = FSMakeFSSpec(vRefNum,dirID,"\pSystem",fileSpec);
-
- if (err) {
- DebugStr("\pFaulty FSMakeFSSpec fails in forming FSSpec.");
- ExitToShell();
- }
- return err;
-
- }
-
- /******
- * Report on what file was selected
- ******/
- void Report(FSSpec *theFile)
- {
- Str27 vRefNumStr;
- Str27 dirIDStr;
-
- NumToString(theFile->vRefNum, vRefNumStr);
- NumToString(theFile->parID, dirIDStr);
- ParamText(theFile->name, vRefNumStr, dirIDStr, "\p");
- Alert(kReportDlgID, nil);
- }
-
- /******
- * Test Displaying folders only, with files within the folders in gray
- ******/
- void TestGetFileGray(void)
- {
- OSErr err;
- FSSpec theFile;
-
- err = SetUpFile(&theFile);
- if (!err)
- {
- err = GetFileGray(&theFile);
- if (!err)
- Report(&theFile);
- }
- }
-
- /******
- * if the isDirectory bit is set, return false (to show the directory)
- * if the isDirectory bit is clear, return true (to filter out all files)
- ******/
- pascal Boolean MyStandardFileFilter(CInfoPBPtr pb, MyDataRecord *myDataPtr)
- {
- return ( !(pb->dirInfo.ioFlAttrib & isDirectory) );
- }
-
- /*****
- * Handle items hit in our dialog
- *****/
- pascal short MyDlgFilter(short item, DialogPtr theDialog, MyDataRecord *myDataPtr)
- {
- if (item == sfHookFirstCall)
- {
- myDataPtr->theReply->sfFile = *(myDataPtr->theFile);
-
- // the following line ensures the first subfolder in the folder specified
- // is selected. If we didn't nil out the name, the last subfolder would
- // be selected.
- myDataPtr->theReply->sfFile.name[0] = 0;
- myDataPtr->theReply->sfScript = 0;
- return sfHookChangeSelection;
- }
- if (item == 10)
- return sfItemOpenButton;
- return item;
- }
-
- /*****
- * Test Displaying folder only, with no files within the folders.
- *****/
- TestGetFileNoGray()
- {
- FSSpec myFSSpec;
- SFTypeList typeList;
- StandardFileReply reply;
- Point where = {-1, -1};
- MyDataRecord myData;
-
- myData.theFile = &myFSSpec;
- myData.theReply = &reply;
-
- SetUpFile(&myFSSpec);
- CustomGetFile((FileFilterYDProcPtr)MyStandardFileFilter,
- -1,
- typeList,
- &reply,
- -6042,
- where,
- (DlgHookYDProcPtr)MyDlgFilter,
- nil,
- 0,
- nil,
- &myData);
- if (reply.sfGood)
- {
- FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, nil, &myFSSpec);
- Report(&myFSSpec);
- }
- }
-
-